package cn.jy.machine.service.impl;

import cn.jy.common.machine.domain.ExpressBoxes;
import cn.jy.common.machine.domain.dto.ExpressBoxUsageRecordsDto;
import cn.jy.common.machine.domain.dto.ExpressBoxesDto;
import cn.jy.common.machine.domain.vo.ExpressBoxUsageRecordsVo;
import cn.jy.machine.mapper.ExpressBoxUsageRecordsMapper;
import cn.jy.machine.mapper.ExpressBoxesMapper;
import cn.jy.machine.service.ExpressBoxesService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

@Service
@Slf4j
public class ExpressBoxesServiceImpl implements ExpressBoxesService {

    @Autowired
    private ExpressBoxesMapper expressBoxesMapper;
    @Autowired
    private ExpressBoxUsageRecordsMapper expressBoxUsageRecordsMapper;

    @Override
    public void updateBox(ExpressBoxes boxes) {
        if (boxes.getStorageType()==1){
            BigDecimal bigDecimal = new BigDecimal("-18");
            boxes.setTemperature(bigDecimal);
        }else {
            boxes.setTemperature(null);
        }
        expressBoxesMapper.updateBox(boxes);
    }

    @Override
    public ExpressBoxesDto findBoxById(Integer id) {
        return expressBoxesMapper.findBoxById(id);
    }

    @Override
    public List<ExpressBoxUsageRecordsDto> list(ExpressBoxUsageRecordsVo vo) {
        return expressBoxUsageRecordsMapper.list(vo);
    }

    @Override
    public Integer count(ExpressBoxUsageRecordsVo vo) {
        return expressBoxUsageRecordsMapper.count(vo);
    }

    @Override
    public Integer newOpenNum() {
        long l = System.currentTimeMillis();
        Integer i = expressBoxUsageRecordsMapper.newOpenNum();
        log.info("用时{}", System.currentTimeMillis()-l);
        return i;
    }
}
